import java.io.*;

class StreamGobbler extends Thread
{
	InputStream is;
	String type;
	boolean output=false;

	StreamGobbler(InputStream is, String type)
	{
		this.is = is;
		this.type = type;
	}
	
	StreamGobbler(InputStream is, String type,boolean output)
	{
		this(is,type);
		this.output=output;
	}

	public void run()
	{
		Message msg;
		try
		{
			InputStreamReader isr = new InputStreamReader(is);
			BufferedReader br = new BufferedReader(isr);
			String line=null;
			while ( (line = br.readLine()) != null)
			{			
				if (type=="ERROR")
					Log.error(line);
				else if (type=="OUTPUT")
					Log.debug(line);
				System.out.println(line);
				if (output) {				
					msg = new Message(MsgCommands.WRITE,line);
					GuiManager.getInstance().pushMessage(msg);
				}
			}
		} catch (IOException ioe)
		{
			Log.writeEx(ioe);  
		}
	}
}